package com.ldzy.webase.exception;

import com.ldzy.webase.utils.Response;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.UnsupportedEncodingException;

/**
 * 异常捕获类
 */
@RestControllerAdvice
public class ExceptionAdvice {
    @ExceptionHandler(ExceptionResponse.class)
    @ResponseBody
    public Response doMyException(ExceptionResponse ex) {
        System.err.println("code:" + ex.getCode() + ",msg:" + ex.getMsg());
        return Response.build(ex.getCode(), ex.getMsg());
    }
}
